![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Common environment detection functions for ilib. iLib is a cross-engine library of internationalization (i18n) classes written in pure JS
Detect various things in the runtime environment.
This package can be used to detect the following things:
See the full API documentation.
npm install ilib-env
or
yarn add ilib-env
Return the name of the platform upon which the code is currently running.
ES2015:
var ilibEnv = require("ilib-env");
var platform = ilibEnv.getPlatform();
ES6:
import { getPlatform } from 'ilib-env';
const platform = getPlatform();
or
import ilibEnv from 'ilib-env';
const platform = ilibEnv.getPlatform();
This will return a string that names the platform upon which the package is running. The string will have one of the following values:
Return the BCP-47 locale specifier for the platform on which this code is running.
ES2015:
var ilibEnv = require("ilib-env");
var locale = ilibEnv.getLocale();
ES6:
import { getLocale } from 'ilib-env';
const locale = getLocale();
or
import ilibEnv from 'ilib-env';
const locale = ilibEnv.getLocale();
If the platform supports the Intl
object, this function will use it to determine
the current locale. (This includes most modern browsers and nodejs). If there is no
Intl
object, or the locale is not specified in the Intl
object, this function
will check various environment variables to find the locale. If none can be found,
it will return a default of "en-US".
Return the IANA timezone specifier for the platform on which this code is running.
ES2015:
var ilibEnv = require("ilib-env");
var timezone = ilibEnv.getTimeZone();
ES6:
import { getTimeZone } from 'ilib-env';
const timezone = getTimeZone();
or
import ilibEnv from 'ilib-env';
const timezone = ilibEnv.getTimeZone();
If the platform supports the Intl
object, this function will use it to determine
the current timezone. (This includes most modern browsers and nodejs). If there is no
Intl
object, or the timezone is not specified in the Intl
object, this function
will check various environment variables to find the timezone. If none can be found,
it will return a default of "local".
Return the name of the browser on which this code is running. If the code is not runningn on a browser (ie. the getPlatform() function does not return "browser") then the return value of this function is undefined.
ES2015:
var ilibEnv = require("ilib-env");
if (ilibEnv.getPlatform() === "browser") {
browser = ilibEnv.getBrowser();
}
ES6:
import { getPlatform, getBrowser } from 'ilib-env';
if (getPlatform() === "browser") {
browser = getBrowser();
}
or
import ilibEnv from 'ilib-env';
if (ilibEnv.getPlatform() === "browser") {
browser = ilibEnv.getBrowser();
}
This function returns one of the following values:
If the browser name cannot be determined, this function returns undefined
You can retrieve the top scope of the platform using the top()
function
and you can check whether or not a variable is defined in the top scope
using the isGlobal()
function.
ES2015:
var ilibEnv = require("ilib-env");
var top = ilibEnv.top();
if (ilibEnv.isGlobal("variableName")) {
// safe to reference variableName
}
ES6:
import { top, isGlobal } from 'ilib-env';
const top = top();
if (isGlobal("variableName")) {
// safe to reference variableName
}
or
import ilibEnv from 'ilib-env';
const top = ilibEnv.top();
if (ilibEnv.isGlobal("variableName")) {
// safe to reference variableName
}
Copyright © 2021-2024, JEDLSoft
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
See CHANGELOG.md
FAQs
Common environment detection functions for ilib. iLib is a cross-engine library of internationalization (i18n) classes written in pure JS
The npm package ilib-env receives a total of 178 weekly downloads. As such, ilib-env popularity was classified as not popular.
We found that ilib-env demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.